#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2022/3/1 10:15
# @Author  : Tianle Hu
# @Site    :
# @File    : app.py.py
# @Software: PyCharm

from pygame import mixer


class Player:
    def __init__(self,file) -> None:
        self.file=file
        self.volume=0.5


    def play(self):
        try:
            mixer.init()
            mixer.music.load(self.file)
            mixer.music.set_volume(self.volume)
            mixer.music.play()
        except:
            pass
        
    def get_busy(self)->bool:
        return mixer.music.get_busy()

    def pause(self):
        mixer.music.pause()

    def unpause(self):
        mixer.music.unpause()

    def volumeAdd(self):
        self.volume+=0.1
        mixer.music.set_volume(self.volume)
        
    def volumeSub(self):
        self.volume-=0.1
        mixer.music.set_volume(self.volume)




# def selectFile():
#     file = filedialog.askopenfile(mode='r', filetypes=[('AudioFile', '*.mp3')])
#     global file
#     file = str(file).split("'")[1]
#     try:
#         playAudio()
#     except:
#         pass


